#import <Foundation/Foundation.h>
#import "NativeFBShareDelegate.h"
#import "FBUnityUtility.h"
#import "UnityInterface.h"
#import "UnityAppController.h"

//Unity 中接收回调消息的游戏对象名称
const char* const GAME_OBJECT_NAME = "PlatformUtils";
//Unity 中处理回调消息的方法名称
const char* const FBUnityMethodName_OnFacebookShareNativeCallback = "FacebookShareCallback";


@implementation NativeFBShareDelegate
#pragma mark - FBSDKSharingDelegate

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
    NSLog(@"FBShareComplete");
    //分享成功，返回字符串“success”
     UnitySendMessage(GAME_OBJECT_NAME, FBUnityMethodName_OnFacebookShareNativeCallback, [[NSString stringWithFormat:@"1|%@", @"complete"] UTF8String]);
}

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    NSLog(@"FBShareError");
    //分享发生错误时，返回字符串“error”
    
    UnitySendMessage(GAME_OBJECT_NAME, FBUnityMethodName_OnFacebookShareNativeCallback,  [[NSString stringWithFormat:@"3|%@", error] UTF8String]);
}

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
    NSLog(@"FBShareCancelled");
    //用户取消了分享，返回字符串“cancelled”
    UnitySendMessage(GAME_OBJECT_NAME, FBUnityMethodName_OnFacebookShareNativeCallback, [[NSString stringWithFormat:@"2|%@", @"canceled"] UTF8String]);
}

@end
